package com.vcredit.creditcat.service;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.ChannelStatisticsConfigOwner_AD;
import com.vcredit.creditcat.vo.ChannelStatisticsConfigOwnerVo;
import com.vcredit.creditcat.framework.pagination.Criteria;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.persistence.base.ChannelStatisticsConfigOwnerMapper;
import com.vcredit.framework.util.BeanUtil;

 /*
  * @author zhangxingong
  * @version 1.0
  * @since 1.0
 */
@Service
public class ChannelStatisticsConfigOwnerService {
    
    @Autowired
	private ChannelStatisticsConfigOwnerMapper channelStatisticsConfigOwnerMapper;
    
	public Page<ChannelStatisticsConfigOwner_AD> findByPage(Criteria criteria){
	    return new Page<ChannelStatisticsConfigOwner_AD>(channelStatisticsConfigOwnerMapper.findByPageCount(criteria), channelStatisticsConfigOwnerMapper.findByPage(criteria));
	}
	
	public List<ChannelStatisticsConfigOwner_AD> find(ChannelStatisticsConfigOwner_AD channelStatisticsConfigOwner){
	    return channelStatisticsConfigOwnerMapper.find(channelStatisticsConfigOwner);
	}
	
	public ChannelStatisticsConfigOwner_AD findById(Long channelId){
	    return channelStatisticsConfigOwnerMapper.findById(channelId);
	}
	
	public List<ChannelStatisticsConfigOwner_AD> findAll(){
	    return channelStatisticsConfigOwnerMapper.findAll();
	}
	
	public void save(ChannelStatisticsConfigOwnerVo channelStatisticsConfigOwnerVo){
	  try {
		  ChannelStatisticsConfigOwner_AD channelStatisticsConfigOwner = new ChannelStatisticsConfigOwner_AD();
	     BeanUtil.copy(channelStatisticsConfigOwnerVo, channelStatisticsConfigOwner);
	     channelStatisticsConfigOwnerMapper.insert(channelStatisticsConfigOwner);
       }catch (Exception e) {
           e.printStackTrace();
       }
	}
	
	public void update(ChannelStatisticsConfigOwner_AD channelStatisticsConfigOwner){
		channelStatisticsConfigOwnerMapper.update(channelStatisticsConfigOwner);
	}
	
	public void removeChannelStatisticsConfigOwner(String ids){
	  for (String channelIdString : ids.split(",")) {
        Long channelId = Long.parseLong(channelIdString);
        channelStatisticsConfigOwnerMapper.delete(channelId);
      }
	}
	
}
